package com.haiertvbic.tvwa.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.haiertvbic.tvwa.protocol.CAEProtocol;
import com.haiertvbic.tvwa.util.SLog;

public class ProgramCachesDate {
	// 频道->最多得倒的节目数
	private static final int PRO_CACHES = 10;
	// 节目->最多得倒的在其它台的节目
	private static final int PRO_CHANNELID = 20;
	// 第一屏能显示多少个频道
	private static final int PRO_NUM = 5;
	private static final String TAG = "ProgramCachesDate";
	// 根据频道id获取到的节目集合
	private static Map<Integer, ArrayList<ProgramBean>> pro_caches = new HashMap<Integer, ArrayList<ProgramBean>>();
	// 根据节目获取到的在其它台播放情况的集合
	private static Map<Integer, ArrayList<ProgramBean>> channel_id = new HashMap<Integer, ArrayList<ProgramBean>>();
	// 分类的map
	private static ArrayList<ProgramItemBean> items = new ArrayList<ProgramItemBean>();

	public static ArrayList<ProgramItemBean> getItems() {
		return items;
	}

	public static void setItems(ArrayList<ProgramItemBean> items) {
		ProgramCachesDate.items = items;
	}

	public static ArrayList<ProgramBean> getPro_caches(int channel_id) {
		return pro_caches.get(channel_id);
	}

	public static void setPro_caches(int channel_id,
			ArrayList<ProgramBean> caches) {
		pro_caches.put(channel_id, caches);
//		FavChannelPagekage favcha =CAEProtocol.getFavChannel(1, 5);
		ArrayList<FavChannelBean> pro = CAEProtocol.getFavChannel(1, PRO_NUM)
				.getChannels();
		int[] five = new int[PRO_NUM];
		for (int j = 0; j < PRO_NUM; j++) {
			// int ii = CAEProtocol.getFavChannel(0,
			// PRO_NUM).getChannels().get(j)
			// .getChannel_id();
			int ii = pro.get(j).getChannel_id();
//			int ii = favcha.getChannels().get(j).getChannel_id();
			SLog.d(TAG, "zui xi ai de wu ge pind dao hao shi :" + ii);
			five[j] = ii;
		}
		//缓存中存储频道的个数
		int pcaches = pro_caches.size();
		int[] map = new int[pcaches];
		int j = 0;
		for (java.util.Map.Entry<Integer, ArrayList<ProgramBean>> i : pro_caches
				.entrySet()) {
			map[j] = i.getKey();
			j += 1;
		}
		SLog.d(TAG, "频道的缓冲长度：" + j);
		// 规定如果大于指定的节目数，移除除此之外的五个元素
		if (pcaches > PRO_CACHES) {
			for (int i = 0; i < pcaches; i++) {
				if (map[i] != five[i]) {
					pro_caches.remove(i);
				}
			}
		}
		
	}

	public static int getsize() {
		// TODO Auto-generated method stub
		return pro_caches.size();
	}

	public static int getproAtIdsize() {
		return channel_id.size();
	}

	public static ArrayList<ProgramBean> getChannel_id(int pro_id) {
		return channel_id.get(pro_id);
	}

	public static void setChannel_id(int pid, ArrayList<ProgramBean> channels) {
		if (channel_id.size() > PRO_CHANNELID) {
			channel_id.remove(channels.get(1).getCid());
		}
		channel_id.put(pid, channels);
	}
}
